/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "server")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Server.findAll", query = "SELECT s FROM Server s"),
    @NamedQuery(name = "Server.findById", query = "SELECT s FROM Server s WHERE s.id = :id"),
    @NamedQuery(name = "Server.findByIdCloudSupplier", query = "SELECT s FROM Server s WHERE s.idCloudSupplier = :idCloudSupplier")})
public class Server implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    @Column(name = "Id_Cloud_Supplier")
    private String idCloudSupplier;
    @OneToMany(mappedBy = "idServer")
    private Collection<Disk> diskCollection;
    @OneToMany(mappedBy = "idServer")
    private Collection<NetworkInterface> networkInterfaceCollection;
    @OneToMany(mappedBy = "idServer")
    private Collection<Cpu> cpuCollection;
    @OneToMany(mappedBy = "idServer")
    private Collection<Memory> memoryCollection;
    @JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Component component;
    @JoinColumn(name = "Id_Rack", referencedColumnName = "ID")
    @ManyToOne
    private Rack idRack;

    public Server() {
    }

    public Server(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIdCloudSupplier() {
        return idCloudSupplier;
    }

    public void setIdCloudSupplier(String idCloudSupplier) {
        this.idCloudSupplier = idCloudSupplier;
    }

    @XmlTransient
    public Collection<Disk> getDiskCollection() {
        return diskCollection;
    }

    public void setDiskCollection(Collection<Disk> diskCollection) {
        this.diskCollection = diskCollection;
    }

    @XmlTransient
    public Collection<NetworkInterface> getNetworkInterfaceCollection() {
        return networkInterfaceCollection;
    }

    public void setNetworkInterfaceCollection(Collection<NetworkInterface> networkInterfaceCollection) {
        this.networkInterfaceCollection = networkInterfaceCollection;
    }

    @XmlTransient
    public Collection<Cpu> getCpuCollection() {
        return cpuCollection;
    }

    public void setCpuCollection(Collection<Cpu> cpuCollection) {
        this.cpuCollection = cpuCollection;
    }

    @XmlTransient
    public Collection<Memory> getMemoryCollection() {
        return memoryCollection;
    }

    public void setMemoryCollection(Collection<Memory> memoryCollection) {
        this.memoryCollection = memoryCollection;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    public Rack getIdRack() {
        return idRack;
    }

    public void setIdRack(Rack idRack) {
        this.idRack = idRack;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Server)) {
            return false;
        }
        Server other = (Server) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Server[ id=" + id + " ]";
    }
    
}
